//-----------------------------------------------------------------------
// <copyright file="a_VoteLog_CartDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_VoteLog_CartDAOBase
    {
        #region Common methods
        public virtual a_VoteLog_Cart Createa_VoteLog_CartFromReader(IDataReader reader)
        {
            a_VoteLog_Cart item = new a_VoteLog_Cart();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("VID"))) item.VID = (int)reader["VID"];
                if (!reader.IsDBNull(reader.GetOrdinal("RID"))) item.RID = (int)reader["RID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CookieID"))) item.CookieID = (string)reader["CookieID"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_VoteLog_Cart methods
            
        public virtual void Createa_VoteLog_Cart(a_VoteLog_Cart a_VoteLog_Cart)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_VoteLog_Cart_ins");
                
                database.AddInParameter(dbCommand, "@RID", DbType.Int32, a_VoteLog_Cart.RID);
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_VoteLog_Cart.CookieID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_VoteLog_Cart.DomainID);
                database.AddOutParameter(dbCommand, "@VID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_VoteLog_Cart.VID = (int)database.GetParameterValue(dbCommand, "@VID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_VoteLog_Cart methods
        
        public virtual void Updatea_VoteLog_Cart(a_VoteLog_Cart a_VoteLog_Cart)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_VoteLog_Cart_upd");            
                
                database.AddInParameter(dbCommand, "@VID", DbType.Int32, a_VoteLog_Cart.VID);
                database.AddInParameter(dbCommand, "@RID", DbType.Int32, a_VoteLog_Cart.RID);
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_VoteLog_Cart.CookieID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_VoteLog_Cart.DomainID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_VoteLog_Cart methods
        public virtual void Deletea_VoteLog_Cart(int vid)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_VoteLog_Cart_del");
                
                database.AddInParameter(dbCommand, "@VID", DbType.Int32, vid);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_VoteLog_Cart methods
        
        public virtual a_VoteLog_Cart Geta_VoteLog_Cart(int vid)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_VoteLog_Cart_sel");
                
                database.AddInParameter(dbCommand, "@VID", DbType.Int32, vid);
                
                a_VoteLog_Cart a_VoteLog_Cart =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_VoteLog_Cart = Createa_VoteLog_CartFromReader(reader);
                        reader.Close();
                    }
                }
                return a_VoteLog_Cart;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_VoteLog_CartList methods
        public virtual a_VoteLog_CartCollection Geta_VoteLog_CartList(a_VoteLog_CartColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_VoteLog_Cart_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_VoteLog_CartCollection a_VoteLog_CartCollection = new a_VoteLog_CartCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_VoteLog_Cart a_VoteLog_Cart = Createa_VoteLog_CartFromReader(reader);
                        a_VoteLog_CartCollection.Add(a_VoteLog_Cart);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_VoteLog_CartCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_VoteLog_CartCollection Geta_VoteLog_CartList(a_VoteLog_CartColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_VoteLog_CartList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}